/**
 * @Description
 * @Author LZL
 * @Date 2025/2/25
 */


package com.kcb.choose;

import com.kcb.coursemanager.printcourse;
import com.kcb.login.login; // 修改导入语句以正确引用 login 类

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class choose extends JFrame {
    private JButton modifyCourseTableButton, viewCourseTableButton, backButton;
    private String username;

    public choose(String username) {
        this.username = username;
        setTitle("城科课程表管理系统:功能选择");
        setSize(450, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        ImageIcon icon = new ImageIcon("C:\\Users\\TBS\\IdeaProjects\\KCB\\image\\ccst.png");
        if (icon != null) {
            setIconImage(icon.getImage());
        } else {
            System.out.println("Failed to load icon image.");
        }


        // 创建主面板
        JPanel panel = new JPanel();
        panel.setBackground(new Color(240, 245, 255));
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(15, 10, 15, 10);
        gbc.fill = GridBagConstraints.HORIZONTAL;

        JLabel titleLabel = new JLabel("课程管理");
        titleLabel.setFont(new Font("宋体", Font.BOLD, 22));
        titleLabel.setForeground(new Color(50, 50, 150));

        modifyCourseTableButton = createStyledButton("修改课程表", new Color(60, 160, 250));
        viewCourseTableButton = createStyledButton("查看课程表", new Color(60, 200, 120));
        backButton = createStyledButton("返回", new Color(220, 80, 80));

        // 添加组件到布局
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.CENTER;
        panel.add(titleLabel, gbc);

        gbc.gridy = 1;
        panel.add(modifyCourseTableButton, gbc);

        gbc.gridy = 2;
        panel.add(viewCourseTableButton, gbc);

        gbc.gridy = 3;
        panel.add(backButton, gbc);

        getContentPane().add(panel);

        // 按钮监听事件
        modifyCourseTableButton.addActionListener(e -> {
            new choose2(username).setVisible(true);
            dispose();
        });

        viewCourseTableButton.addActionListener(e -> new printcourse(username).setVisible(true));

        backButton.addActionListener(e -> {
            new login().setVisible(true);
            dispose();
        });
    }

    private JButton createStyledButton(String text, Color bgColor) {
        JButton button = new JButton(text);
        button.setFont(new Font("宋体", Font.BOLD, 16));
        button.setBackground(bgColor);
        button.setForeground(Color.WHITE);
        button.setFocusPainted(false);
        button.setBorderPainted(false);
        button.setPreferredSize(new Dimension(180, 45));
        return button;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new choose("exampleUser").setVisible(true));
    }
}